/**
 * @author LKQ
 * @date 2021/12/11 17:32
 * @description 正序
 */
public class Solution1 {
    public static void main(String[] args) {
        Solution1 solution = new Solution1();
        int[] prices = {7, 2, 5, 3, 6, 1, 8};
        solution.maxProfit(prices);
    }

    public int maxProfit(int[] prices) {
        int minPrice = Integer.MAX_VALUE;
        int maxProfit = 0;
        for (int i = 0; i < prices.length; i++) {
            if (prices[i] < minPrice) {
                minPrice = prices[i];
            } else if (prices[i] - minPrice > maxProfit) {
                maxProfit = prices[i] - minPrice;
            }
        }
        return maxProfit;
    }
}
